from machine import Pin, SPI
import st7789
import time, gc

"""
    使用该程序，程序提前刷带st7789的固件程序，固件下载地址https://github.com/nspsck/st7735s_WeAct_Studio_TFT_port
    下载后进入st7735s_WeAct_Studio_TFT_port-main/firmware/ESP32_GENERIC目录，获取firmware.bin固件进行刷写
"""
def config(rotation=0, options=0):
    return st7789.ST7789(
        SPI(2, baudrate=30000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(23)),
        128,
        160,
        reset=Pin(19, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(4, Pin.OUT),
        rotation=rotation,
        options=options,
        use_drawbuffer=True,
        reversed_backlight=True)

tft = config(0)
tft.init()
tft.png(f'/image/sheep.png', 0, 0)
time.sleep(2)
gc.collect()
tft.jpg(f'/image/heart.jpg', 0, 0)
time.sleep(2)
gc.collect()

while True:
    # 循环显示每张图片
    for i in range(1,7):
        tft.jpg(f'/jpg/img{i}.jpg', 0, 0)
        time.sleep(2)

    gc.collect()#释放内存
 
